<include file="Public:top" />
	<div data-role="header" data-position="fixed">
	    <a href="__APP__" data-rel="back">后退</a><h1>收货信息</h1><a href="__APP__" data-rel="back">首页</a>
	</div>
    <div data-role="content">      
    	<form method="post" data-transition="pop" id="address" class="address" name="address" action="{:U('Couponorder/insert')}" enctype="multipart/form-data" >        
		<div data-role="fieldcontain">
			<label for="name"><strong class="red">*</strong>收货人</label>
			<input type="text" name="name" id="name" value="" placeholder="请填写收货人姓名">
		</div>
		<div data-role="fieldcontain">
			<label for="mobile"><strong class="red">*</strong>手机号</label>
			<input type="text" name="mobile" id="mobile" value="" placeholder="请填写收货人手机号">
		</div>
		<div data-role="fieldcontain">
			<label for="province" class="select"><strong class="red">*</strong>省份/直辖市</label>
			<select id="province" name="province" onchange="loadRegion('province',2,'city','{:U('Ajax/getRegion')}');">
				<option value="" selected>请选择省份</option>
			    <volist name="province" id="vo"> 
			    <option value="{$vo.id}" >{$vo.name}</option>
		        </volist>
			</select>
		</div>
		<div data-role="fieldcontain">
			<label for="city" class="select"><strong class="red">*</strong>市/县</label>
			<select id="city" name="city"  onchange="loadRegion('city',3,'town','{:U('Ajax/getRegion')}');">
				<option value="" selected>请选择市县</option>
			</select>
		</div>
		<div data-role="fieldcontain">
			<label for="town" class="select">区/镇</label>
			<select id="town" name="town" >
				<option value="" selected>请选择区域</option>
			</select>
		</div>
		
		<div data-role="fieldcontain">
		    <label for="address"><strong class="red">*</strong>详细地址</label>
		    <textarea name="address" id="address" placeholder="请填写尽可能详细的地址"></textarea>
		</div>
		
		<div data-role="fieldcontain">
		    <label for="remark">备注</label>
		    <textarea name="remark" id="remark" placeholder="其他要求可以填写在这里"></textarea>
		</div>
		
		<div data-role="fieldcontain">
		    <label for="remark">提示</label>
		    <span class="red"> 同城（常州）默认发EMS,统一上午9:00发货；其他地区默认发顺丰，统一下午3:00发货；如需修改，请在备注中说明。 </span>
		</div>
		
		<input type="button" name="submit" id="submitbtn" value="提交"  />
		</form>
    </div>
    <script>
    $(function(){
	   	$("#submitbtn").bind("click",function()
		{
	   		name = $("#name").val();
	   		mobile = $("#mobile").val();
	   		province = $("#province").val();
	   		city = $("#city").val();
	   		town = $("#town").val();
	   		address = $("#address").text();
	   		
	   		if(!name){
	   			alert('姓名不能为空！'); return false;
	   		}
	   		
	   		if(name.length<2){
	   			alert('姓名格式错误！'); return false;
	   		}
	   		
	   		if(!mobile){
	   			alert('手机号码不能为空！'); return false;
	   		}
	   		
	   		if(mobile.length != 11){
	   			alert('手机号码格式错误！'); return false;
	   		}
	   		
	   		if(!province){
	   			alert('请选择所在省份！'); return false;
	   		}
	   		
	   		if(!city){
	   			alert('请选择所在城市！'); return false;
	   		}
	   		
	   		if(!town){
	   			//alert('请选择所在区域！'); return false;
	   		}
	   		
	   		if(!address){
	   			alert('请先写详细地址！'); return false;
	   		}

	   		var formData = $("#address").serialize();
	   		
            $.ajax({
                type: "POST",
                url: "{:U('Couponorder/insert')}",
                cache: false,
                data: formData,
                dataType: "json",
                success: function(data){
                	if(data.status == 1){
                		alert(data.info);
                		setTimeout(function(){
            				window.location.href="{:U('Couponorder/myads')}"; 
    					},1000);
					}else{
						alert(data.info);
					}
                },
                error: function(data){
                	alert('提交失败！');
                }
            });
	   		
            return false;
		});
	});
    
    
    //地区联动选择
	function loadRegion(sel,type_id,selName,url){
		jQuery("#"+selName+" option").each(function(){
			jQuery(this).remove();
		});
		jQuery("<option value=0>请选择</option>").appendTo(jQuery("#"+selName));
		if(jQuery("#"+sel).val()==0){
			return;
		}
		jQuery.getJSON(url,{pid:jQuery("#"+sel).val(),type:type_id},
			function(data){
				if(data){
					jQuery.each(data,function(idx,item){
						jQuery("<option value="+item.id+">"+item.name+"</option>").appendTo(jQuery("#"+selName));
					});
				}else{
					jQuery("<option value='0'>请选择</option>").appendTo(jQuery("#"+selName));
				}
			}
		);
	}
	</script>
	<include file="Couponorder:footer" />
<include file="Public:bottom" />